package com.you.rpc.base;

import com.you.rpc.until.HessianUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class ObjectEncoder extends MessageToByteEncoder<Object> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object o, ByteBuf byteBuf) throws Exception {
        byte[] bytes = HessianUtil.hessianSerialize(o);
        int len = bytes.length;
        byteBuf.writeInt(len).writeBytes(bytes);
    }
}
